home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 2869 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: soap.news.pipex.net!pipex!usenet
  2. From: m.hendry@dial.pipex.com (Mathew Hendry)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: AMIGA-E? Factorial
  5. Date: Tue, 6 Feb 96 12:59:42
  6. Organization: Private node.
  7. Distribution: world
  8. Message-ID: <19960206.45EBC8.BED2@al048.du.pipex.com>
  9. References: <4f29da$s37$1@mhadg.production.compuserve.com>
  10. NNTP-Posting-Host: al048.du.pipex.com
  11. X-Newsreader: TIN [AMIGA 1.3 950726BETA PL0]
  12.  
  13. alt.amiga.demos (100627.1346@CompuServe.COM) wrote:
  14. : I would just like to no how you can do large factorials in amiga E
  15. : arfter trying the example in the manual , it doesnt seem to handle
  16. : numbers larger than 25 how can you get around this.
  17.  
  18. This could be a stack overflow problem, due to depth of recursion (is the
  19. factorial function you're using recursive or iterative?), but it's more
  20. likely that you've simply reached the size limit for the integers you are
  21. using (probably 32 bit). You could solve this in two ways:
  22.  
  23. 1) Use floating point numbers, and inevitably lose precision.
  24.  
  25. 2) Emulate larger integers by "joining" two or more regular integers together,
  26.    either in a structure or as separate variables. You will need to write
  27.    extra arithmetic functions to deal with these new data types and handle
  28.    overflows etc. There _may_ be pre-built E modules to do things like this,
  29.    but since I haven't used E, I couldn't give you a firm answer.
  30.  
  31. Method 1 is obviously the easiest, but as I say, you lose precision doing it
  32. this way, and you will run into limits with these types as well, once the
  33. exponent of the factorial goes out of range (the factorial function grows
  34. _very_ quickly). With emulated integers of arbitrary length, on the other
  35. hand, you are effectively limited only by available memory, and should be
  36. able to calculate some very large factorials.
  37.  
  38. -- Mat.
  39.